// 监听到popup.js消息
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    test_dom()
})

function test_dom() {
    // 通过谷歌浏览器bug进行添加信任事件

    window.addEventListener('mousedown', onDownEvent);
    window.addEventListener('mouseup', onUpEvent);

    action_dom()
}
function action_dom() {
    let nav_dom = $(".zcy-panel-header-title")[0]
    console.log(nav_dom)

    nav_dom.addEventListener('mousedown', function(e) {
        console.log("...点击按钮 mousedown...")
        console.log(e)
        e.preventDefault();

        let obj = { eventPlease: "trusted", x: 0, y: 0, mouse: "D" }
        chrome.runtime.sendMessage(obj, function (response) {
            console.log("...content mousedown action_dom response...");
            console.log(response);
        });

    }, true);

    let clickEvent = document.createEvent('MouseEvents');
    clickEvent.initEvent('mousedown', true, true);
    nav_dom.dispatchEvent(clickEvent);




    // 弹起
    nav_dom.addEventListener('mouseup', function(e) {
        console.log("...点击按钮 mouseup ...")
        console.log(e)
        e.preventDefault();

        let obj = { eventPlease: "trusted", x: 0, y: 0, mouse: "U" }
        chrome.runtime.sendMessage(obj, function (response) {
            console.log("...content mouseup action_dom response...");
            console.log(response);
        });

    }, true);
    let click2Event = document.createEvent('MouseEvents');
    click2Event.initEvent('mouseup', true, true);
    nav_dom.dispatchEvent(click2Event);

}

function onDownEvent(e) {
    console.log("...onDownEvent...")
    console.log(e);
}
function onUpEvent(e) {
    console.log("...onUpEvent...")
    console.log(e);
}